package cxf.client;

import cxf.server.pojo.User;
import cxf.server.service.HelloWorld;
import cxf.server.service.UserService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

public class ClientTest {

    public static void main(String[] args){
        cl2();
    }

    /**
     * 方式1.代理类工厂的方式,需要拿到对方的接口
     */
    public static void cl1(){
        // 接口地址
        String address = "http://localhost:8080/webservice/helloWorld?wsdl";
        // 代理工厂
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        // 设置代理地址
        jaxWsProxyFactoryBean.setAddress(address);
        // 设置接口类型
        jaxWsProxyFactoryBean.setServiceClass(HelloWorld.class);
        // 创建一个代理接口实现
        HelloWorld cs = (HelloWorld) jaxWsProxyFactoryBean.create();
        // 数据准备
        String userName = "Leftso";
        // 调用代理接口的方法调用并返回结果
        String result = cs.sayHi(userName);
        System.out.println("返回结果:" + result);
    }

    public static void cl2(){
        // 接口地址
        String address = "http://localhost:8080/webservice/user?wsdl";
        // 代理工厂
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        // 设置代理地址
        jaxWsProxyFactoryBean.setAddress(address);
        // 设置接口类型
        jaxWsProxyFactoryBean.setServiceClass(UserService.class);
        // 创建一个代理接口实现
        UserService cs = (UserService) jaxWsProxyFactoryBean.create();
        // 调用代理接口的方法调用并返回结果
        User result = cs.getUser();
        System.out.println("返回结果:" + result.getCreateDate());
    }
}
